package com.fingard.net.listener;

import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.util.Date;
import java.util.HashMap;

public class HttpReceiver {

    public String ip;
    public int port;
    public int seqIDInner;
    public Date connTime;
    public boolean isCompleted;
    public Date recCompleteTime;
    public byte[] recBytes;

    public int contentLength;
    public int contentStartIndex;

    public int readedLength;

    public Socket socketClient;
    public String initCharset;

    public String sourceIP;
    
    public String connState;
    public String connMsg;

    public HttpReceiver(Socket p_socket, String p_initCharset) {
        socketClient = p_socket;
        initCharset = p_initCharset;
        reset();
    }

    public HashMap<String, String> headKV;

    public void reset() {
        contentLength = -1;
        contentStartIndex = -1;
        readedLength = 0;
        isCompleted = false;
        headKV = new HashMap<String, String>();
    }
    
    /**获取收到的报文，去掉通讯头部字节*/
    public String getContentString(String pCharset) throws UnsupportedEncodingException{
    	if(readedLength>0){
    		return new String(recBytes, contentStartIndex, contentLength, pCharset);
    	}else{
    		return "";
    	}
    }
    
    /**获取收到的所有字符*/
    public String getFullString(String pCharset) throws UnsupportedEncodingException{
    	if(readedLength>0){
    		return new String(recBytes, 0, readedLength, pCharset);
    	}else{
    		return "";
    	}
    }
}
